// See the Electron documentation for details on how to use preload scripts:
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts

import { ipcRenderer, contextBridge } from 'electron'
import {Config, LoadedData} from "./common/types";
import {IPC_FUNC_LOAD_DATA, IPC_SYS_CONFIG, IPC_SYS_OS_VERSION,} from "./common/IpcChennelNames";

contextBridge.exposeInMainWorld("__INFO__",{
    SERVICE_MODE:process.env.NODE_ENV,
})

contextBridge.exposeInMainWorld("API",{
    config:()=>{
        return new Promise<Config>((resolve, reject) => {
            ipcRenderer.invoke(IPC_SYS_CONFIG)
                .then(res=>{
                    resolve(res);
                })
                .catch(reject);
        })
    },
    osVersion:()=>{
      return new Promise<string>((resolve, reject) => {
          ipcRenderer.invoke(IPC_SYS_OS_VERSION).then(resolve).catch(reject);
      })
    },
    loadData:()=>{
        return new Promise<LoadedData>((resolve, reject) => {
            ipcRenderer.invoke(IPC_FUNC_LOAD_DATA).then(resolve).catch(reject);
        })
    }
})
